
clear
cd ..\cps
set mem 300m
set more off

*smoking information of other household members
clear
foreach name in may06 aug06 jan07 {
      use "cps`name'.dta",clear
	keep if pea1==1 | pea1==2
	keep hrhhid pea3 prs64
	ren hrhhid hhid
	ren pea3 pes34 
	gen smoke=(pes34==1|pes34==2)
	*total numer of smoking person in the household
	by hhid, sort: egen tsm = total(smoke)
	*keep only self-respondent
	keep if prs64==1	
	keep hhid tsm
	sort hhid
	save t`name'c, replace
        }

clear
foreach name in may06 aug06 jan07 {
      use "cps`name'.dta",clear
	*ren pec6e pec6d2
	keep peio1cow hrhhid pulineno hrmis hrmonth hryear peage hufaminc hrnumhou pemaritl peeduca ptdtrace prdthsp pea2 peda peb2 pec2 /*
*/ ped2 peg1 pemlr pea3 peb6a peb6b peb6c peb6d1 peb6d2 peb7 pec7d peb8 pec1 pec1a pec6a pec6b pec6c pec6d1 pec6d2 pec8 peh6 peb1 pesex /*
*/ gestfips pwsrwgt pea1 prs64 peb5anum peb5aunt pec5anum pec5aunt gtcbsa gtco gtcbsast gtcbsasz gereg prmjocc1 peb6e* pec6e*
	keep if pea1==1 | pea1==2
	*keep only self-respondent
	keep if prs64==1	
	ren hrnumhou hhsize
	ren hrmonth month
	ren hryear year
	ren peage age
	ren pesex sex
	ren ptdtrace race
	ren prdthsp origin
	ren peeduca edu
	ren gestfips state
	ren peb1 cigday
	ren pemaritl marstat
	ren hufaminc faminc
	ren pwsrwgt srwgt
	ren hrhhid hhid
	*ren huhhnum hhnum
	ren pulineno lineno
	ren hrmis mis
	ren pea3 pes34 
	ren pea2 pes33
	ren peb8 pes61 
	replace pes61=pec8 if pes61<0 & pec8>0
	replace pes61=peh6 if pes61<0 & peh6>0
	keep peio1cow hhid lineno mis year month age sex faminc hhsize edu race origin marstat state cigday pes34 pes61 srwgt peb2 pec2 /*
*/ peda ped2 peg1 pes33 pemlr peb6a peb6b peb6c peb6d1 peb6d2 peb7 pec7d pec1 pec1a pec6a pec6b pec6c pec6d1 pec6d2 peb5anum peb5aunt /*
*/ pec5anum pec5aunt gtcbsa gtco gtcbsast gtcbsasz gereg prmjocc1 peb6e* pec6e*

	sort hhid
	merge hhid using t`name'c
	keep if _merge==3
	drop _merge
	save t`name', replace
        }


use tmay06,clear 
foreach name in aug06 jan07 {
	append using t`name'
	}
/*
sort state year month
merge state year month using cigtaxprice3
keep if _merge==3
drop _merge
*/
save merge2006, replace

/*
insheet using cbsa.csv
sort cbsa
save cbsa,replace
*/
